import Router from '@koa/router';
import { validateDto } from '../../../middleware/validation';
import { AuthMiddleware } from '../../../middleware/authMiddleware';
import { DicController } from '../../../controllers/system/dicController';
import { CreateDicDto, UpdateDicDto } from '../../../dtos/system/DicDto';

const router = new Router();
const dicController = new DicController();
const authMiddleware = new AuthMiddleware();

// 获取所有字典项（需要认证）
router.get('/', authMiddleware.authenticate, dicController.getDics);

// 根据Type获取字典项（需要认证）
router.get('/:type', authMiddleware.authenticate, dicController.getDicByType);

// 创建字典项（需要认证，仅管理员）
router.post('/', authMiddleware.authenticate, validateDto(CreateDicDto), dicController.createDic);

// 更新字典项（需要认证，仅管理员）
router.put('/:id', authMiddleware.authenticate,  validateDto(UpdateDicDto, { skipMissingProperties: true }), dicController.updateDic);

// 删除字典项（需要认证，仅管理员）
router.delete('/:id', authMiddleware.authenticate, authMiddleware.requireRole('admin'), dicController.deleteDic);

export default router;